import * as React from 'react';
import {View, Text, SafeAreaView} from 'react-native';
import {reducer, context, initState} from './store';
import API from './api';
import ATest from './components/ATest';
import BTest from './components/BTest';

const {useContext, useReducer} = React;

function App() {
  console.log('欢迎进入React-Native调试页面');
  const store = useReducer(reducer, initState);
  const testPress = () => {
    API.testAPI.GetTest().then(res => {
      console.log(res);
    });
  };
  const testGetParams = () => {
    API.testAPI.GetTestB({theName: 'getTest', method: 'get'}).then(res => {
      console.log(res);
    });
  };
  const testPost = () => {
    API.testAPI.PostTest({theName: 'postName'}).then(res => {
      console.log(res);
    });
  };
  return (
    <context.Provider value={store}>
      <SafeAreaView>
        <View>
          <Text>这是首页</Text>
        </View>
        <View style={{marginTop: 100}}></View>
        <View>
          <Text onPress={testPress}>发送get请求</Text>
        </View>
        <View>
          <Text onPress={testGetParams}>发送get请求(携带参数)</Text>
        </View>
        <View>
          <Text onPress={testPost}>发送post请求</Text>
        </View>
        <ATest></ATest>
        <BTest></BTest>
      </SafeAreaView>
    </context.Provider>
  );
}

export default App;
